/**
 * Created by lintao_alex on 2018/6/28.
 */


namespace game{
    import Texture = egret.Texture;
    import EgretFactory = dragonBones.EgretFactory;

    export class SkeletonMaker{
        static readonly armatureName = 'Armature';
        static readonly slotName = 'slot';
        static readonly
        static parseTexture(texture:Texture, name:string, transform?:{x?:number,y?:number,scX?:number,scY?:number,skX?:number,skY?:number}, factory?:EgretFactory){
            let texWidth = texture.textureWidth;
            let texHeight = texture.textureHeight;
            let skeJson:any = {name:name,version:5.5};
            let armatureJson:any = {type:"Armature",name:this.armatureName};
            armatureJson.aabb = {width:texWidth, height:texHeight};
            armatureJson.bone = [{name:'root'}]
            armatureJson.slot = [{name:this.slotName,parent:'root'}]
            let display:any = {name:name};
            if(transform) display.transform = transform
            armatureJson.skin = [{slot:[{name:this.slotName,display:[display]}]}]
            skeJson.armature = [armatureJson]
            let texJson:any = {name:name}
            texJson.SubTexture = [{width:texWidth,height:texHeight,name:name,x:1,y:1}]
            texJson.width = texWidth;
            texJson.height = texHeight;

            if(!factory) factory = EgretFactory.factory;
            factory.parseDragonBonesData(skeJson, name);
            factory.parseTextureAtlasData(texJson, texture, name);
        }
    }
}